
package system.base;

import java.util.ArrayList;
import java.util.List;
import framework.core.*;
import system.LoginContext;
import system.SelectManager;
import system.data.*;

/*
	Author    :Wing
	CreateTime:2008-02-20 18:11:02
*/
public class OutSub extends OutSubBase 
{

    public static final String STATUS_AVALIBLE = "1"; //有效状态
    public static final String STATUS_NOTAVALIBLE = "0"; //无效状态
    
//----system generated start----// 	
public OutSub() 
{
	
}

private static void delete(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	delete(con,TABLE_NAME,conditions);
}
public static OutSub fetch()
{   
	return new OutSub();
}
public static OutSub copy(OutSub srcObj)
{
	OutSub obj = fetch();
	obj.copyBase(srcObj);
	return obj;
}
public static OutSub fetch(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	return fetch(con,conditions);
}
public static OutSub fetch(DBConnection con,Conditions conditions) throws Exception
{
	DBResult result = null;
	try
	{
		result = DBEngine.doSelect(con,"select * from " + TABLE_NAME,conditions);
		java.sql.ResultSet rs = result.getRs();
		OutSub obj = null;
		if(rs.next())
		{
			obj = fetch(rs);
		}
		return obj;
	}
	finally
	{
		if(result!=null) result.clear() ;
	}
}
public static OutSub fetch(java.sql.ResultSet rs) throws Exception
{
	OutSub obj = new OutSub();
	obj.initObject(rs);
	return obj;
}
protected void getUnique(DBConnection con) throws Exception
{
		setId(DBEngine.getId(con));
}
//----system generated end----//



//----add by Wing start----//
public static OutSub fetchByOutBillId(DBConnection con,String outBillId) throws Exception
{
    Conditions conditions = new Conditions();

    conditions.add(OUT_BILL_ID,outBillId);
    
    return fetch(con,conditions);
}

//----add by Wing end----//

public String viewBalanceMode(DBConnection con) throws Exception
{
    String mReturn = SelectManager.viewBalanceModel(getBalanceMode());
    return mReturn;
}

public String viewProviderName(DBConnection con)throws Exception
{
    Provider obj= new Provider();
    obj= Provider.fetchByCode(con, getProviderCode());
    String name;
    if(obj == null) name = "";
    else{
        name = obj.viewName(con);
    }    
    return name;
}

public String viewProductCount(DBConnection con) throws Exception
{
    return StringUtil.showCount(String.valueOf(getProductCount()));
}

public static List getLast5OutSub(DBConnection con, LoginContext loginInfo) throws Exception{
    String warehouseCode = loginInfo.getWarehouse().getCode();
    //String preWarehouseCode = ConstDefine.getWildCard(warehouseCode);
    List list = new ArrayList();
    
    String sql = "select * from ( " +
                 "select head.out_time, sub.* from t_out_head head " +
                 "left join t_out_sub sub on sub.out_bill_code = head.out_bill_code "; 
    
    //if(!"000000".equals(loginInfo.getWarehouse().getCode())){
        sql = sql + "where head.warehouse_code like '" + warehouseCode + "%' and sub.status = '1' and head.out_time > to_char(sysdate-7,'yyyy-mm-dd hh24:mi:ss') ";
    //}            
    
    sql = sql + "order by head.out_time desc ) " +
           "where rownum < 6";
    
    DBResult result = null;
    try
    {
        result = DBEngine.doSelect(con, sql);
        java.sql.ResultSet rs = result.getRs();
        OutSub obj = null;
        while(rs.next())
        {
            obj = fetch(rs);
            list.add(obj);
        }
    }
    finally
    {
        if(result!=null) result.clear() ;
    }
    
    return list;
}

}

